package InvestmentPojo;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import adminLoginPack.FemaUtilAuthenticate;

import ImmovableIndia.ConnectionPool;
import ImmovableIndia.serviceManagerImpl;
import Notifications.notificationsDataLoading;



public class UIFormLeftMenuAction extends Action {

	private static final Logger logger = Logger.getLogger(UIFormAction.class);
	  public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		  ResultSet rs = null;
		  Connection con=null;
		  Statement st = null;
		  String str = "";
		  String method = null;
		  String returnTableData = null;
		  String forwardPage = null; 
		  String showToolPage = null;
		  FileInputStream fis ;
		  notificationsDataLoading  ndb = null;
		  List li = null;
		 
		  try{
			  	String methodName = request.getParameter("methodName");
			  	serviceManagerImpl smp = new serviceManagerImpl();
			    method = null != request.getParameter("a")?request.getParameter("a"):"";
			  	String UserIDForservice = null != request.getParameter("UserIDForservice")? request.getParameter("UserIDForservice"):"";
			  	String circularNumbers = "";
			  	List optionsList123=new ArrayList();
			  	ndb = new notificationsDataLoading();
			  	 String userId = null != request.getParameter("UserID")? request.getParameter("UserID"):"";
				  
				  if("".equals(userId)){
					  userId = null != request.getSession().getAttribute("UserID")?(String)request.getSession().getAttribute("UserID"):"";
				  }
				  String path = request.getSession().getServletContext().getRealPath("/");
			  	if(null != method){

			  		
					
					  if(method.trim().equals("Notifications")){
						  
						  request.setAttribute("showUserToolPage", "");
						  
						  
						  li = ndb.getNotificationObject("",UserIDForservice ,"notification");
						  request.setAttribute("returnList", li);
						  
						 String websiteTitles = ndb.getNotificationTitles("notification", UserIDForservice, "type");
						  
						  logger.debug("Notifications......Loaded Successfully."+UserIDForservice);
						  forwardPage = "notifications";
						  
						  //String labelArray[] = websiteTitles.split("~~");
							 
						  request.setAttribute("headerTitle", websiteTitles);

						  //request.setAttribute("headerTitle1", (null != labelArray && labelArray.length>2)?labelArray[2]:"");

						   
						  request.setAttribute("TOOL", "1");
						  request.setAttribute("UserIDForservice", UserIDForservice);
						  logger.debug("notification data Loading");
						 
					  }else if(method.trim().equals("Circulars") || method.trim().equals("MasterCirculars")){
						  
						  if(method.trim().equals("MasterCirculars")){
						  returnTableData = smp.getsMasterCircularsData(UserIDForservice, "master_circulars", "");
						  logger.debug("MasterCirculars data Loaded"+UserIDForservice);
						  }else {
							  logger.debug("Circulars data Loading"+UserIDForservice);
							  //returnTableData = smp.getCircularsData(UserIDForservice, "circulars", "");
						  }
						  li = ndb.getCircularsObject(UserIDForservice, "circulars","");
						  request.setAttribute("returnList", li);
						  String websiteTitles = ndb.getWebsiteTitles("circulars", UserIDForservice, "type");
						  if(null != websiteTitles && !"".equals(websiteTitles)){
						  request.setAttribute("headerTitle", websiteTitles);
						  }else request.setAttribute("headerTitle", "");
						  logger.debug("Circulars......Loaded Successfully."+UserIDForservice);
						  request.setAttribute("UserIDForservice", UserIDForservice);
						  forwardPage = "circulars";
						 
						  
						   
					  }else if(method.trim().equals("DEFINITIONS")){
						  
						  li = ndb.getDefinitionsDataLoading(UserIDForservice, "definitions","");
						  request.setAttribute("returnList", li);
						  
						  
						  String websiteTitles = ndb.getWebsiteTitles("definitions", UserIDForservice, "Definition_Name");
						  if(null != websiteTitles){
						  String labelArray[] = websiteTitles.split("~~");
						 
						  request.setAttribute("headerTitle", labelArray[1]);

						  request.setAttribute("headerTitle1",(null != labelArray && labelArray.length>2)? labelArray[2]:"");
						  }
						  request.setAttribute("UserIDForservice", UserIDForservice);
						  
						  request.setAttribute("headerTitleRupee", "");
						  logger.debug("DEFINITIONS......Loaded Successfully."+UserIDForservice);
						  forwardPage = "definitions";
					  }}else {
						  if("".equals(showToolPage) && !showToolPage.equals("showToolPage")){
							FemaUtilAuthenticate femaUtil = new FemaUtilAuthenticate();
							  
							  boolean isUserExist = femaUtil.isUserExist(request, response,userId);
							  if(!isUserExist){
								  forwardPage =  "authfailed";
							  }
						  }
						}
			         
			  		request.setAttribute("ServiceID", UserIDForservice);
					 
			             
			              
			              if(method.trim().equals("4") || method.trim().equals("3") || method.trim().equals("6") || method.trim().equals("8") || method.trim().equals("withoutuser")){
			            	  response.getWriter().write(str); 
			              }
			         
					  
			  	
				
				
				
		  }catch(Exception e){
			  e.printStackTrace();
		  }finally{
			 
		  }
		  return mapping.findForward(forwardPage);
	  }
	 
}
